#!/usr/bin/perl -w
my $copyright = 'Copyright (C) 2007,2009,2012,2014,2015,2016 Olly Betts';
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA

use strict;

my $generated_warning =
"/* Warning: This file is generated by $0 - do not modify directly! */\n";

my %uncopyableclasses = (
);

my %copyableclasses = (
    'FeatureVector' => ''
);

my %no_get_description = (
    'FeatureVector' => '',
    'Feature' => '',
    'FeatureList' => '',
    'Letor' => '',
    'ListNETRanker' => '',
    'NDCGScore' => '',
    'SVMRanker' => ''
);

print <<'END';
/** @file
 * @brief test common features of API classes
 */
END
print $generated_warning;
print <<"END";
/* $copyright
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
 */

#include <config.h>

#include "api_generated.h"

#define XAPIAN_DEPRECATED(D) D
#include <xapian.h>
#include <xapian-letor.h>

#include "apitest.h"
#include "testutils.h"

using namespace std;

/// Check uncopyable API classes which should have a default ctor actually do.
DEFINE_TESTCASE(defaultctor1, !backend) {
END

for my $class (sort keys %uncopyableclasses) {
    my $params = $uncopyableclasses{$class};
    if ($params ne '') {
	$params = "($params)";
    }
    my $get_description = ! exists $no_get_description{$class};
    my $object = lc $class;
    $class = "Xapian::$class";
    print "    $class $object$params;\n";
    print "    TEST(!$object.get_description().empty());\n" if $get_description;
}

print <<'END';
}

/// Test that API classes have a copy ctor and assignment operator.
DEFINE_TESTCASE(copyassign1, !backend) {
END

for my $class (sort keys %copyableclasses) {
    my $params = $copyableclasses{$class};
    if ($params =~ /INMEMORY/) {
	print "#ifdef XAPIAN_HAS_INMEMORY_BACKEND\n";
    }
    if ($params ne '') {
	$params = "($params)";
    }
    my $get_description = ! exists $no_get_description{$class};
    my $object = lc $class;
    $class = "Xapian::$class";
    print "    $class $object$params;\n";
    print "    TEST(!$object.get_description().empty());\n" if $get_description;
    print "    $class copy_$object($object);\n";
    print "    $object = copy_$object;\n";
    if ($params =~ /INMEMORY/) {
	print "#endif\n";
    }
    print "\n";
}

print <<'END';
}
END
